package com.property.manage.service.repair;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guardchina.framework.mybatis.model.CustomPage;
import com.guardchina.framework.util.exception.BusinessException;
import com.guardchina.framework.util.utils.PhoneUtil;
import com.property.manage.dao.renovation.RenovationMapper;
import com.property.manage.dao.repair.RepairMapper;
import com.property.manage.model.renovation.RenovationEntity;
import com.property.manage.model.renovation.RenovationVo;
import com.property.manage.model.repair.RepairEntity;
import com.property.manage.model.repair.RepairVo;
import com.property.manage.model.resource.BuildingVo;
import com.property.manage.service.renovation.DepositService;
import com.property.manage.service.resource.BuildingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

/**
 * 描述
 *
 * @author lwb
 * @since 2020/7/15
 */
@Component
@Slf4j
public class RepairService {
    @Autowired
    private RepairMapper repairMapper;

    public RepairVo findById(Integer id) {
        return repairMapper.queryById(id);
    }

    public CustomPage<RepairVo> page(Long pageNo, Long pageSize, Integer villageId, String startTime, String endTime) {
        Page<RepairVo> page = new Page<>(pageNo, pageSize);

        IPage<RepairVo> village =repairMapper.getPage(page,villageId,startTime,endTime);
        return new CustomPage<>(village);
    }

    @Transactional(rollbackFor = Exception.class)
    public void add(Integer villageId, String content,String name, String phone,
                    LocalDate rTime
    ) {
        RepairEntity entity = new RepairEntity();
        entity.setContent(content);
        entity.setName(name);
        entity.setPhone(phone);
        entity.setRTime(rTime);
        entity.setVillageId(villageId);
        repairMapper.insert(entity);
    }




    @Transactional(rollbackFor = Exception.class)
    public void update(Integer id, Integer villageId, String content,String name, String phone,
                       LocalDate rTime,String personnel,LocalDate pTime  ) {

        UpdateWrapper<RepairEntity> wrapper = new UpdateWrapper<>();
        wrapper.set("village_id",villageId);
        wrapper.set("content", content);
        wrapper.set("name", name);
        wrapper.set("phone", phone);
        wrapper.set("r_time", rTime);
        wrapper.set("personnel", personnel);
        wrapper.set("p_time", pTime);
        wrapper.eq("id", id);

            repairMapper.update(null, wrapper);

    }


    public void delete(Integer id) {
        repairMapper.deleteById(id);
    }




}
